import { RouteObject, UIMatch } from 'react-router'

/**
 * 路由配置项附加信息
 * @example const matches = useMatches() as UIMatch<unknown, IRouteHandle | undefined>[]
 */
export interface IRouteHandle {
  /** 名称，用于页面标题、面包屑导航 */
  name: (match: UIMatch<unknown, IRouteHandle>) => string
  /** 隐藏左侧菜单栏 */
  hideLeftSider?: boolean
  /** 隐藏面包屑导航 */
  hideBreadcrumb?: boolean
  /** 无布局，hideLeftSider、hideBreadcrumb 将失败 */
  noLayout?: boolean
}

/**
 * 路由配置项
 */
export interface TRoute<TRequiredHandle = false, TPathPrefix extends string = string>
  extends Omit<RouteObject, 'handle' | 'index'> {
  path: `${TPathPrefix}${string}`
  handle: TRequiredHandle extends true ? IRouteHandle : IRouteHandle | undefined
  children?: TRoute<true, TPathPrefix>[]
}
